package com.zpark.mapper;

import com.zpark.pojo.Account;
import com.zpark.pojo.vo.AccountToUser;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @PackageName: com.zpark.mapper
 * @ClassName: IAccountMapper
 * @Description:
 * @author: RZS
 * @date: 2023/4/24  15:31
 */
public interface IAccountMapper {

    // 查询账户数据，并查询与之关联的用户数据
    @Select("select id, uid, money from account")
    @Results(id = "accountToUser", value = {
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "uid", column = "uid"),
            @Result(property = "money", column = "money"),

            @Result(property = "user", column = "uid",
            one = @One(select = "com.zpark.mapper.IUserMapper.selectUserById",
                    fetchType = FetchType.LAZY))
    })
    List<AccountToUser> selectAll();

    @Select("select id, uid, money from account where id=#{uid}")
    Account selectById(Integer uid);
}
